package com.ysy.tz.mfg.component;

import com.ysy.tz.core.engine.ApplicationContext;
import com.ysy.tz.core.utils.FileResourceLoader;
import java.io.IOException;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;

public class MenuButton extends AnchorPane {
    private String text;
    private ImageView imageView = new ImageView();
    private Label label = new Label();
    private Label remarkLabel = new Label();
    private static Image commonImageView;

    public MenuButton(String text, String remark, String imageUrl) {
        double percentage = ApplicationContext.mainStage.getWidth() / 1920.0;
        this.text = text;
        this.label.setText(text);
        this.label.setAlignment(Pos.CENTER_RIGHT);
        this.label.setPrefHeight(percentage * 40.0);
        this.imageView.setFitHeight(percentage * 50.0);
        this.imageView.setFitWidth(percentage * 50.0);
        this.label.setStyle("-fx-background-color: rgb(89,18,14);");
        this.label.setTextFill(Color.WHITE);
        this.setStyle("-fx-font-size: 16;-fx-background-color: white;");
        this.remarkLabel.setWrapText(true);
        this.remarkLabel.setAlignment(Pos.TOP_LEFT);
        this.remarkLabel.setText(remark);
        this.remarkLabel.setStyle("-fx-border-insets:0;-fx-border-width:0;-fx-font-size: 12;");

        try {
            this.imageView.setImage(new Image(FileResourceLoader.loadInputStream("/views/images/" + imageUrl)));
        } catch (Exception var7) {
            this.imageView.setImage(commonImageView);
            var7.printStackTrace();
        }

        this.getChildren().add(this.remarkLabel);
        this.getChildren().add(this.label);
        this.getChildren().add(this.imageView);
        setTopAnchor(this.imageView, percentage * 10.0);
        setLeftAnchor(this.imageView, percentage * 10.0);
        setLeftAnchor(this.remarkLabel, percentage * 50.0);
        setTopAnchor(this.remarkLabel, percentage * 10.0);
        setRightAnchor(this.remarkLabel, percentage * 10.0);
        setBottomAnchor(this.remarkLabel, percentage * 5.0);
        setLeftAnchor(this.label, percentage * 10.0);
        setRightAnchor(this.label, percentage * 10.0);
        setBottomAnchor(this.label, percentage * 5.0);
    }

    public void setMenuViewName(final String menuViewName) {
        this.setOnMousePressed(new EventHandler<MouseEvent>() {
            public void handle(MouseEvent event) {
                try {
                    ApplicationContext.mainPage.loadCenterPage(menuViewName.substring(4));
                    ((FuncBanner)ApplicationContext.mainPage.getTopBanner()).setFuncLabel(MenuButton.this.text);
                } catch (IOException var3) {
                    var3.printStackTrace();
                }

            }
        });
    }

    protected void layoutChildren() {
        double size = this.getWidth() > this.getHeight() ? this.getHeight() - 20.0 : this.getWidth() - 20.0;
        setLeftAnchor(this.remarkLabel, size + 10.0);
        this.imageView.setFitWidth(size);
        this.imageView.setFitHeight(size);
        super.layoutChildren();
    }

    static {
        try {
            commonImageView = new Image(FileResourceLoader.loadInputStream("/views/images/man.png"));
        } catch (IOException var1) {
            var1.printStackTrace();
        }

    }
}
